package cn.sdormitory.smartdor.service.impl;

import cn.sdormitory.dormitoryHygiene.dao.DormitoryHygieneDao;
import cn.sdormitory.dormitoryHygiene.dao.DormitoryHygieneItemDao;
import cn.sdormitory.dormitoryHygiene.dao.DormitoryHygieneStudentDao;
import cn.sdormitory.dormitoryHygiene.entity.DormitoryHygieneItem;
import cn.sdormitory.dormitoryHygiene.entity.DormitoryHygieneStudent;
import cn.sdormitory.dormitoryHygiene.req.DormitoryHygieneListReq;
import cn.sdormitory.dormitoryHygiene.vo.DormitoryHygieneCountVO;
import cn.sdormitory.dormitoryHygiene.vo.ExportDormitoryHygieneVO;
import cn.sdormitory.smartdor.service.DormitoryHygieneService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author : yy
 * @date: 2024/9/24 15:04
 * @description:
 */
@Service
public class DormitoryHygieneServiceImpl implements DormitoryHygieneService {
    @Resource
    private DormitoryHygieneDao dormitoryHygieneDao;
    @Resource
    private DormitoryHygieneItemDao hygieneItemDao;
    @Resource
    private DormitoryHygieneStudentDao hygieneStudentDao;

    @Override
    public IPage<DormitoryHygieneCountVO> listDormitoryHygiene(DormitoryHygieneListReq hygieneListReq) {
        IPage<DormitoryHygieneCountVO> page =  new Page<>(hygieneListReq.getPageNum(), hygieneListReq.getPageSize());
        dormitoryHygieneDao.listDormitoryHygiene(page, hygieneListReq);
        return page;
    }

    @Override
    @Transactional
    public void deleteByIds(Long[] ids) {
        List<Long> idList = Arrays.asList(ids);
        dormitoryHygieneDao.deleteBatchIds(idList);
        LambdaQueryWrapper<DormitoryHygieneItem> hygieneItemWrapper = new LambdaQueryWrapper<>();
        hygieneItemWrapper.in(DormitoryHygieneItem::getDormitoryHygieneId,idList);
        hygieneItemDao.delete(hygieneItemWrapper);
        LambdaQueryWrapper<DormitoryHygieneStudent> hygieneStudentWrapper = new LambdaQueryWrapper<>();
        hygieneStudentWrapper.in(DormitoryHygieneStudent::getDormitoryHygieneId,idList);
        hygieneStudentDao.delete(hygieneStudentWrapper);
    }

    @Override
    public List<ExportDormitoryHygieneVO> getDormitoryHygieneCountExport(DormitoryHygieneListReq hygieneListReq) {
        return dormitoryHygieneDao.getDormitoryHygieneCountExport(hygieneListReq);
    }
}
